package cn.com.controller;

import cn.com.pojo.Food;
import cn.com.pojo.User;
import cn.com.service.FoodService;
import cn.com.service.UserService;
import com.alibaba.fastjson.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/foods")
public class FoodController {

        @Resource
        private FoodService foodService;
     @RequestMapping(value = "/list",method = RequestMethod.POST)
     @ResponseBody
     public Object find(){
         List<Food> list = foodService.find();
         Map<String,Object> map=new HashMap<>();
         map.put("list",list);
         return JSONArray.toJSONString(map);
     }



        @RequestMapping(value = "/getFoods",method = RequestMethod.POST)
        @ResponseBody
        public Object find2(@RequestParam("id") Integer id){
            Food food = foodService.findById(id);
            return JSONArray.toJSONString(food);
        }
}
